<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('采购清单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>合同编号：</label>
                                <input type="text" name="contractCode"/>
                            </li>
                            <li>
                                <label>供应商名称：</label>
                                <input type="text" name="supplierName"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="productName"/>
                            </li>
                            <li>
                                <label>订货人：</label>
                                <input type="text" name="purchaser"/>
                            </li>
                            <li>
                                <label>是否含税：</label>
                                <select name="isTaxIncluded">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </li>
                            <li>
                                <label>是否到货：</label>
                                <select name="isDelivered">
                                    <option value="">所有</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </li>
                            <li>
                                <label>发票情况：</label>
                                <select name="invoiceStatus">
                                    <option value="">所有</option>
                                    <option value="0">未开票</option>
                                    <option value="1">已开票</option>
                                    <option value="2">部分开票</option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="purchase:purchaseList:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="purchase:purchaseList:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="purchase:purchaseList:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="purchase:purchaseList:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('purchase:purchaseList:edit')}]];
        var removeFlag = [[${@permission.hasPermi('purchase:purchaseList:remove')}]];
        var detailFlag = [[${@permission.hasPermi('purchase:purchaseList:detail')}]];
        var prefix = ctx + "purchase/purchaseList";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "采购清单",
                sortName: "purchaseListId",
                sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'purchaseListId',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'contractCode',
                    title: '合同编号'
                },
                {
                    field: 'supplierName',
                    title: '供应商名称'
                },
                {
                    field: 'productName',
                    title: '产品名称'
                },
                {
                    field: 'totalAmount',
                    title: '金额',
                    formatter: function(value, row, index) {
                        return value ? '￥' + value : '';
                    }
                },
                {
                    field: 'orderQuantity',
                    title: '定货数量'
                },
                {
                    field: 'isTaxIncluded',
                    title: '是否含税',
                    formatter: function(value, row, index) {
                        if (value == '1') {
                            return '<span class="label label-success">是</span>';
                        } else if (value == '0') {
                            return '<span class="label label-danger">否</span>';
                        }
                        return '';
                    }
                },
                {
                    field: 'isDelivered',
                    title: '是否到货',
                    formatter: function(value, row, index) {
                        if (value == '1') {
                            return '<span class="label label-success">已到货</span>';
                        } else if (value == '0') {
                            return '<span class="label label-warning">未到货</span>';
                        }
                        return '';
                    }
                },
                {
                    field: 'invoiceStatus',
                    title: '发票情况',
                    formatter: function(value, row, index) {
                        if (value == '未开票' || value == '0') {
                            return '<span class="label label-danger">未开票</span>';
                        } else if (value == '已开票' || value == '1') {
                            return '<span class="label label-success">已开票</span>';
                        } else if (value == '部分开票' || value == '2') {
                            return '<span class="label label-warning">部分开票</span>';
                        }
                        return '';
                    }
                },
                {
                    field: 'purchaser',
                    title: '订货人'
                },
                {
                    field: 'contractDate',
                    title: '合同日期'
                },
                {
                    field: 'paymentDate',
                    title: '付款日期'
                },
                {
                    field: 'arrivalDate',
                    title: '到货日期'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.purchaseListId + '\')" title="详情"><i class="fa fa-eye"></i>详情</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.purchaseListId + '\')" title="编辑"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.purchaseListId + '\')" title="删除"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        // 详情操作
        $.operate.detail = function(id) {
            var url = prefix + '/detail/' + id;
            $.modal.openTab("采购清单详情", url);
        }
    </script>
</body>
</html>